<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">任务审核</block>
			<block slot="right">
				<view style="color: #fff;margin-right: 20rpx;" @click="shenhe">审核</view>
			</block>
		</cu-custom>

		<scroll-view scroll-y class="page">
			<view style="height: 10rpx;"></view>
			<view class="cu-list menu card-menu margin-bottom-xl shadow-lg radius " style="background-color: #fff;">
				<view class="u-header"><text class="tips">任务编号:</text><text class="val">{{data.taskCode}}</text></view>
				<view class="u-body">
					<view class="row">
						<view class="tips">任务类型</view>
						<view class="val">{{this.data.taskType == 1 ? '常规' : (this.data.taskType == 2 ? '送样' : this.data.taskType)}}</view>
					</view>
					<view class="row">
						<view class="tips">委托单位</view>
						<view class="val">{{data.entrustCompanyName}}</view>
					</view>
					<view class="row">
						<view class="tips">检测单位</view>
						<view class="val">{{data.assayCompanyName}}</view>
					</view>
					<view class="row">
						<view class="tips">来源方式</view>
						<view class="val">{{this.data.sourceType == null ? '/' : data.sourceType}}</view>
					</view>
					<view class="row">
						<view class="tips">备样方案</view>
						<view class="val">{{data.backSamplePlanId == null ? '/' : data.backSamplePlanId}}</view>
					</view>
					<view class="row">
						<view class="tips">化验项目</view>
						<view class="val">{{this.itemCodes == '' ? '/' : this.itemCodes}}</view>
					</view>
					<view class="row">
						<view class="tips">备注</view>
						<view class="val">{{data.note == '' ? '/' : data.note}}</view>
					</view>
				</view>
			</view>

		</scroll-view>
		<view class="cu-modal bottom-modal" :class="modalName=='confirm'?'show':''" @tap="hideModal">
			<view class="cu-dialog" @tap.stop="">
				<view class="cu-bar bg-white">
					<view class="action text-blue" @tap="pass(0)">驳回</view>
					<view class="action text-green" @tap="pass(1)">通过</view>
				</view>
				<view style="height: 200rpx;font-size: 30rpx;">
					<view class="inputbox">
						<text class="lg cuIcon-edit"></text>
						<input class="f_input" placeholder="拒绝理由" v-model="param.opinion" />
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				modalName: null,
				data: {},
				itemCodes: '',
				param: {
					opinion: null,
					status: 102,
					t: 0,
					taskId: 0,
					todoId: 0
				},
			}
		},
		onShow() {
			this.data = uni.getStorageSync("AUDIT_DATA");
			this.param.taskId = this.data.taskId;
			this.param.todoId = this.data.todoId;
			var itemArr = JSON.parse(this.data.assayItem);
			this.itemCodes = '';
			for (var i = 0; i < itemArr.length; i++) {
				this.itemCodes += itemArr[i].itemCode + ',';
			}
			if (this.itemCodes.lastIndexOf(",") != -1) {
				this.itemCodes = this.itemCodes.substring(0, this.itemCodes.length - 1);
			}
		},
		methods: {
			shenhe: function() {
				this.modalName = "confirm";
			},
			hideModal: function() {
				this.modalName = null;
			},
			pass: function(f) {
				if (f == 1) {
					this.param.status = 102;
					uni.request({
						url: this.$http + '/biz/bizTask/update',
						data: this.param,
						header: {
							token: uni.getStorageSync("token")
						},
						method: 'POST',
						success: (res) => {
							if (res.statusCode == 200 && res.data.code == 0) {
								this.modalName = null;
								uni.showToast({
									icon: 'none',
									title: '操作成功！'
								});
								uni.navigateBack();
							} else {
								uni.showToast({
									icon: 'none',
									title: '操作失败，请重试！'
								});
							}
						},
						fail: function() {
							uni.showToast({
								icon: 'none',
								title: '服务器请求超时！'
							});
						}
					})
				} else {
					this.param.status = 103;
					this.param.itemList = [];
					uni.request({
						url: this.$http + '/biz/bizTask/update',
						data: this.param,
						header: {
							token: uni.getStorageSync("token")
						},
						method: 'POST',
						success: (res) => {
							if (res.statusCode == 200 && res.data.code == 0) {
								this.modalName = null;
								uni.showToast({
									icon: 'none',
									title: '操作成功！'
								});
								uni.navigateBack();
							} else {
								uni.showToast({
									icon: 'none',
									title: '操作失败，请重试！'
								});
							}
						},
						fail: function() {
							uni.showToast({
								icon: 'none',
								title: '服务器请求超时！'
							});
						}
					})
				}
			},
		}
	}
</script>

<style>
	.inputbox {
		margin: 0 auto;
		width: 700rpx;
		height: 80rpx;
		border: 1px #D0D0D0 solid;
		border-radius: 10rpx;
		font-size: 30rpx;
		color: #116AB7;
		line-height: 80rpx;
		padding-left: 20.41rpx;
		display: flex;
		margin-top: 10rpx;
	}

	.f_input {
		text-align: left;
		width: 500rpx;
		height: 50rpx;
		margin-left: 20.83rpx;
		margin-top: 15rpx;
	}

	.selectbox {
		margin: 0 auto;
		width: 700rpx;
		height: 80rpx;
		border-radius: 10rpx;
		font-size: 30rpx;
		color: #116AB7;
		line-height: 80rpx;
		display: flex;
		margin-top: 10rpx;
		justify-content: space-between;
	}
	.no-data {
		  text-align: center;
	}
</style>
